//
//  LGHomeViewCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/21.
//

#import "LGHomeViewCell.h"

@interface LGHomeViewCell()
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipIcon;
/**  风险预警 */
@property (nonatomic , strong)UILabel *riskLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel2;
/**   */
@property (nonatomic , strong)UILabel *followContent;

@end

@implementation LGHomeViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    if([LGNSString(dataDic[@"sex"]) length] == 0 || [LGNSString(dataDic[@"age"]) length] == 0){
        self.ageLabel.text = [NSString stringWithFormat:@"%@  %@",dataDic[@"sex"],dataDic[@"age"]];
    }else{
        self.ageLabel.text = [NSString stringWithFormat:@"%@ | %@",dataDic[@"sex"],dataDic[@"age"]];
    }
    CGFloat leftMargin = ([LGNSString(dataDic[@"sex"]) length] == 0 && [LGNSString(dataDic[@"age"]) length] == 0)?0:viewPix(6);
    [self.vipIcon mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(leftMargin);
    }];
    self.vipIcon.hidden = [dataDic[@"is_vip"] integerValue]>0?NO:YES;
    [self.vipIcon sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"vipicon"])]];
    NSString *warn = LGNSString(dataDic[@"is_warn"]);
    if ([warn isEqualToString:@"1"]) {
        //低风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"低风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#31A861"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#31A861"].CGColor;
        
    }else if ([warn isEqualToString:@"2"]){
        //中风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"中风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#CD8F47"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#CD8F47"].CGColor;
        
    }else if ([warn isEqualToString:@"3"]){
        //高风险
        self.riskLabel.hidden = NO;
        self.riskLabel.text = @"高风险";
        self.riskLabel.textColor = [UIColor colorWithString:@"#CA0505"];
        self.riskLabel.layer.borderColor = [UIColor colorWithString:@"#CA0505"].CGColor;
    }else{
        self.riskLabel.hidden = YES;
    }
    
    self.contentLabel2.text = @"";
    NSString *type = LGNSString(dataDic[@"type"]);
    NSString *tipStr = LGNSString(dataDic[@"follow_type"]);
    NSMutableString *title = [NSMutableString stringWithString:LGNSString(dataDic[@"title"])];
    if (title.length == 4) {
        [title insertString:@"\n" atIndex:2];
    }
    self.typeLabel.text = title;
    if([type isEqualToString:@"cept"]){
        //心肺运动
        self.typeLabel.textColor = [UIColor colorWithString:@"#56BEA0"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#EBF8F3"];
        self.contentLabel.text = @"测试院区：";
        self.contentLabel2.text = LGNSString(dataDic[@"visit_address_short"]);
        NSString *color = [LGNSString(dataDic[@"visit_address_short"]) isEqualToString:@"温江院区"]?@"#DD3030":@"#666666";
        self.contentLabel2.textColor = [UIColor colorWithString:color];
        
    }else if ([type isEqualToString:@"video"]){
        //视频咨询
        self.typeLabel.textColor = [UIColor colorWithString:@"#EDA436"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#FFF1CF"];
        self.contentLabel.text = [NSString stringWithFormat:@"[%@]%@",tipStr,dataDic[@"follow_needs"]];
        
    }else if ([type isEqualToString:@"followup"]){
        //线下咨询
        self.typeLabel.textColor = [UIColor colorWithString:@"#6A85E5"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#F0F3FF"];
        self.contentLabel.text = [NSString stringWithFormat:@"[%@]%@",tipStr,dataDic[@"follow_needs"]];
        
    }else if ([type isEqualToString:@"visit"]){
        //慢病复查
        self.typeLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#EBF4FF"];
        self.contentLabel.text = [NSString stringWithFormat:@"[%@]%@",tipStr,dataDic[@"follow_needs"]];
    }else if ([type isEqualToString:@"phone"]){
        //电话咨询
        self.typeLabel.textColor = [UIColor colorWithString:@"#5EA446"];
        self.typeLabel.backgroundColor = [UIColor colorWithString:@"#CFEFC4"];
        self.contentLabel.text = [NSString stringWithFormat:@"[%@]%@",tipStr,dataDic[@"follow_needs"]];
    }
    
    CGFloat contentWidth = [self.contentLabel.text textWidthWithFont:LGFont(14) maxHeight:MAXFLOAT];
    contentWidth = (contentWidth>Screen_W-viewPix(87))?(Screen_W-viewPix(87)):contentWidth;
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(contentWidth+1));
    }];
    
    //症状描述
    NSString *followContent = LGNSString(dataDic[@"follow_content"]);
    self.followContent.text = followContent;
    CGFloat followTop = (followContent.length>0)?viewPix(5):0;
    [self.followContent mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(followTop);
    }];
    
    self.statusLabel.text = LGNSString(dataDic[@"followup_no"]);
    self.statusLabel.textColor = [UIColor colorWithString:LGNSString(dataDic[@"followup_no_color"])];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.typeLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.ageLabel];
    [self.contentView addSubview:self.vipIcon];
    [self.contentView addSubview:self.riskLabel];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.contentLabel2];
    [self.contentView addSubview:self.followContent];
    [self.contentView addSubview:self.lineView];
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(12));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.width.height.equalTo(@(viewPix(46)));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.typeLabel).offset(2);
        make.left.equalTo(self.typeLabel.mas_right).offset(viewPix(8));
        make.height.equalTo(@(viewPix(23)));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.vipIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.riskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(viewPix(34)));
        make.height.equalTo(@(viewPix(14)));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.width.equalTo(@(viewPix(10)));
    }];
    [self.contentLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLabel.mas_right);
        make.centerY.equalTo(self.contentLabel);
    }];
    [self.followContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.right.equalTo(self.statusLabel);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(viewPix(5));
        make.bottom.equalTo(self.contentView).offset(-viewPix(12));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(13, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:2];
        _typeLabel.cornerRidus = 5;
    }
    return _typeLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.layer.borderColor = [UIColor colorWithString:@"#333333"].CGColor;
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)vipIcon{
    if(!_vipIcon){
        _vipIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
        _vipIcon.hidden = YES;
    }
    return _vipIcon;
}

-(UILabel *)riskLabel{
    if(!_riskLabel){
        _riskLabel = [UILabel lableWithText:@"" colorString:@"#31A861" textFont:LGFont(10) textAlignment:NSTextAlignmentCenter lines:1];
        _riskLabel.layer.borderWidth = 0.5;
        _riskLabel.cornerRidus = 2;
    }
    return _riskLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#3291FF" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}

-(UILabel *)contentLabel2{
    if(!_contentLabel2){
        _contentLabel2 = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _contentLabel2;
}

-(UILabel *)followContent{
    if(!_followContent){
        _followContent = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _followContent;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#EEF6FF"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
